#ifndef     __STEAM_HEAT_TASK_H
#define     __STEAM_HEAT_TASK_H

#include "../rtos/thread.h"
#include "../rtos/message_queue.h"


namespace task {

class SteamHeatTask : public rtos::Thread<SteamHeatTask, 1024, osPriorityHigh1> {

public:
    enum class State : uint8_t {
        WORK = 0,
        IDLE = 1,
        STOP = 2,
        TIMEOUT = 3,
        FAIL = 4,
    };

    void init_start() {
        m_mq.init();
        this->start();
    }

    void idle() {
        m_mq.post(State::IDLE);
    }
    void stop() {
        m_mq.post(State::STOP);
    }

    uint8_t state() { return static_cast<uint8_t>(m_state); }

    void run();

private:
    void do_idle();
    void do_work();
    void do_stop();
    void do_fail();

    bool wait(uint32_t timeout = osWaitForever) {
        return osOK == m_mq.poll(m_state, timeout);
    }

    State m_state = State::IDLE;
    rtos::MessageQueue<State, 2> m_mq;
};

extern SteamHeatTask steamHeatTask;

}



#endif
